/**
 * 
 */
package edu.sjtu.seda.test;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import edu.sjtu.seda.event.Event;
import edu.sjtu.seda.event.EventHandler;

/**
 * @author john.zhu
 *
 */
public class WriteToFile implements EventHandler {

	/* (non-Javadoc)
	 * @see edu.sjtu.seda.event.EventHandler#handle(edu.sjtu.seda.event.Event)
	 */
	@Override
	public void handle(Event event) {
		if(event instanceof Message){
			Message msg = (Message) event;
			File file = new File("d://a.txt");
			FileWriter write = null;
			try {
				write = new FileWriter(file,true);
				write.write(msg.getMessage());
				
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally{
				try {
					write.close();
//					System.out.println(msg.getMessage()+" has been written to file");
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}

}
